package stableproject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

import japa.parser.ast.Comment;
import japa.parser.ast.CompilationUnit;

public class Node {
	CompilationUnit compUnit;
	String name = "";
	String filename;
	HashMap<String, List> methodHash;
	ArrayList<String> publicMethods;
	String extendz;
	int noKids;
	int dit;

	public Node(CompilationUnit cu, String f)
			throws NullCompilationUnitException {
		if (cu == null)
			throw new NullCompilationUnitException();
		filename = f;
		compUnit = cu;
		publicMethods = new ArrayList<String>();
		methodHash = new HashMap<String, List>();

	}

	/**
	 * Set the classname
	 * 
	 * @param n
	 */
	public void setName(String n) {
		this.name = n;
	}

	/**
	 * Get the filename
	 * 
	 * @return
	 */
	public String getFilename() {
		return filename;
	}

	/**
	 * Return the number of comments
	 * 
	 * @return
	 */
	public int getCommentCount() {
		if (compUnit.getComments() != null)
			return compUnit.getComments().size();
		else
			return 0;

	}

	/**
	 * Return a list of comments
	 */
	public List<Comment> getComments() {
		return compUnit.getComments();

	}

	/**
	 * Add an associated public method
	 * 
	 * @param s
	 */
	public void addPublicMethod(String s) {
		publicMethods.add(s);
	}

	/**
	 * Set what this class extends
	 * 
	 * @param extendz2
	 */
	public void setExtends(String extendz2) {
		this.extendz = extendz2;
	}

	/**
	 * Get what this class extends
	 * 
	 * @return
	 */
	public String getExtends() {
		if (extendz != null)
			return extendz;
		else
			return "";
	}

	/**
	 * Get the classname
	 * 
	 * @return
	 */
	public String getClassName() {
		return this.name;
	}

	/**
	 * Set the NOC
	 * 
	 * @param i
	 */
	public void setNoKids(int i) {
		this.noKids = i;

	}

	/**
	 * Set the DIT
	 * 
	 * @param i
	 */
	public void setDIT(int i) {
		this.dit = i;

	}

	/**
	 * Get the DIT
	 * 
	 * @return
	 */
	public int getDIT() {
		return this.dit;
	}

	/**
	 * Set the method hashmap
	 * 
	 * @param ml
	 */
	public void setmethodHash(HashMap<String, List> ml) {

		methodHash.putAll(ml);

	}

	/**
	 * Print the parameters of each method
	 */
	public void printParamList() {

		Iterator<String> it = methodHash.keySet().iterator();

		System.out.println("\t Count \t Method");
		while (it.hasNext()) {
			String meth = it.next();
			if (methodHash.get(meth) != null)
				System.out.println("\t " + methodHash.get(meth).size() + "\t" + meth);

		}

	}

}
